*********************************************************
*********************************************************  
*** GBR 2024 --- JPE Revision Package *******************
*** Code to prepare the dataset of Study 6 **************
*** Public (anonymized) *********************************
*********************************************************

** Note: this code is use for cleaning the dataset for Study 6. It has been 
* already pre-cleaned before, including for anonymization.

clear all
use ".../JPEReplicationPackageDataverse/GBR24DataStudy6.dta"

set more off
destring, replace


** Create control variables
* Age: age
gen age60=0  if age!=.
replace age60=1 if age>=60 & age!=.
gen age50=0 if age!=.
replace age50=1 if age>=50 & age<60
gen age40=0  if age!=.
replace age40=1 if age>=40 & age<50
label variable age40 "Age 40-49 indicator: 0No 1Yes"
label variable age50 "Age 50-59 indicator: 0No 1Yes"
label variable age60 "Age 60+ indicator: 0No 1Yes"

* Ethnicity: white vs. non-white indicator
gen white=0 if ethnicity!=""
replace white=1 if ethnicity=="White/Caucasian"
replace white=. if  ethnicity=="CONSENT REVOKED"
label variable white "White (vs. non-white) indicator: 0No 1Yes"

* Re-code and re-scale questionnaire questions post experiment, common Studies 1--3
* PE1, understand instructions
gen PE1_UnderstandInst=PE1-1
label variable PE1_UnderstandInst "Common: Understood instructions scale: 0 (not at all) to 6 (very well)"
* PE3, trust instructions
gen PE3_TrustInst=PE3-1
label variable PE3_TrustInst "Common: Trusted instructions scale: 0 (not at all) to 6 (completely)"
* PE4, discussed study before participating
gen PE4_DiscussSomeoneElse=PE4
label variable PE4_DiscussSomeoneElse "Common: Discussed study with other Prolific user who participated before study: 0No 1Yes"
* PE5, helped by someone else
gen PE5_HelpSomeoneElse=PE5
label variable PE5_HelpSomeoneElse "Common: Completed this study with the help of someone else: 0No 1Yes"
* PE6, participated in similar experiment before
gen PE6_ParticipatedSimilarExp=PE6
label variable PE6_ParticipatedSimilarExp "Common: Participated in similar experiment before: 0No 1Yes"
* PE7, knew someone else participating in same experiment
gen PE7_KnowSomeoneElse=PE7-1
label variable PE7_KnowSomeoneElse "Knew someone participating in same experiment: 0No 1Yes"
* PE10, believed could reward experimenters by completing more lines or hurt them by completing fewer lines
gen PE10_BeliefReward_withmorelines=PE10-1
label variable PE10_BeliefReward_withmorelines "Believed reward experimenter with lines: 0 (not at all) to 6 (completely)"
* PE12, previous experience of discrimination (outside experiment, PE12:6 means participant did not want to answer)
gen PE12_PreviouslyDiscriminated=PE12-1 if PE12!=6
label variable PE12_PreviouslyDiscriminated "Previous experience of gender disc: 0 (not at all) to 4 (a great deal)"
* PE13, previous experience of discrimination in workplace (PE13:6 means participant did not want to answer)
gen PE13_PreviouslyDiscriminatedWork=PE13-1 if PE13!=6 
label variable PE13_PreviouslyDiscriminatedWork "Previous workplace experience of gender disc: 0 (not at all) to 4 (a great deal)"
* PE14, belief how much women earn vs. men, on average in UK for full-time job
gen PE14_GenderEarningGapOverall=PE14-1 if PE14!=16 & PE14!=17
label variable PE14_GenderEarningGapOverall "Belief wom earn vs man, fulltime job: 0(65%-) 7(100%) 14(135%+)"
* PE15, belief how much women earn vs. men doing the same full-time job with the same work characteristics (e.g., competence, education, hours worked, management skills, productivity), on average in UK
gen PE15_GenderEarningGapSameWorkers=PE15-1 if PE15!=16 & PE15!=17
label variable PE15_GenderEarningGapSameWorkers "Belief wom earn vs man w/ same charact, fulltime job: 0(65%-) 7(100%) 14(135%+)"

* PNE1, emotions (intensity of each emotion, rescale: 0 to 6)
gen intensity_anger=PEN1_anger-1
label variable intensity_anger "How intensely felt anger: 0 (not at all) to 6 (very intensely)"
gen intensity_surprise=PEN1_surprise-1
label variable intensity_surprise "How intensely felt surprise: 0 (not at all) to 6 (very intensely)"
gen intensity_happiness=PEN1_happiness-1
label variable intensity_happiness "How intensely felt happiness: 0 (not at all) to 6 (very intensely)"
gen intensity_disgust=PEN1_disgust-1
label variable intensity_disgust "How intensely felt disgust: 0 (not at all) to 6 (very intensely)"
gen intensity_sadness=PEN1_sadness-1
label variable intensity_sadness "How intensely felt sadness: 0 (not at all) to 6 (very intensely)"
gen intensity_fear=PEN1_fear-1
label variable intensity_fear "How intensely felt fear: 0 (not at all) to 6 (very intensely)"
gen intensity_guilt=PEN1_guilt-1
label variable intensity_guilt "How intensely felt guilt: 0 (not at all) to 6 (very intensely)"
gen intensity_irritation=PEN1_irritation-1
label variable intensity_irritation "How intensely felt irritation: 0 (not at all) to 6 (very intensely)"
gen intensity_gratitude=PEN1_gratitute-1
label variable intensity_gratitude "How intensely felt gratitute: 0 (not at all) to 6 (very intensely)"
* PEN2, motivation (or work morale) during task (rescale: 0 to 6)
gen work_moral_motivation=PEN2-1
label variable work_moral_motivation "Motivated to work during task: 0 (not at all) to 6 (completely)"
* PEN3, frustration during task (rescale: 0 to 6)
gen work_moral_frustrated=PEN3-1
label variable work_moral_frustrated "Felt frustrated during task: 0 (not at all) to 6 (completely)"

* Create indicator for UK nationality
gen nat_uk=0 if nationality!="" 
replace nat_uk=1 if nationality=="United Kingdom" 
label variable nat_uk "Nationality indicator: 0Non-UK 1UK"

* Create indicator for students
gen student=0 if student_status=="No"
replace student=1 if student_status=="Yes"
label variable student "Student indicator: 0No 1Yes"

* Create employment status indicators
gen employed=.
replace employed=1 if employment_status=="Full-Time"
replace employed=0 if employment_status=="Not in paid work (e.g. homemaker', 'retired or disabled)"
replace employed=0 if employment_status=="Other"
replace employed=0 if employment_status=="Due to start a new job within the next month"
replace employed=0 if employment_status=="Part-Time"
replace employed=0 if employment_status=="Unemployed (and job seeking)"
label variable employed "E: Employed full time indicator: 0No 1Yes"

gen unemployed=.
replace unemployed=0 if employment_status=="Full-Time"
replace unemployed=0 if employment_status=="Not in paid work (e.g. homemaker', 'retired or disabled)"
replace unemployed=0 if employment_status=="Other"
replace unemployed=0 if employment_status=="Due to start a new job within the next month"
replace unemployed=0 if employment_status=="Part-Time"
replace unemployed=1 if employment_status=="Unemployed (and job seeking)"
label variable unemployed "E: Unemployed indicator: 0No 1Yes"

gen parttime=.
replace parttime=0 if employment_status=="Full-Time"
replace parttime=0 if employment_status=="Not in paid work (e.g. homemaker', 'retired or disabled)"
replace parttime=0 if employment_status=="Other"
replace parttime=0 if employment_status=="Due to start a new job within the next month"
replace parttime=1 if employment_status=="Part-Time"
replace parttime=0 if employment_status=="Unemployed (and job seeking)"
label variable parttime "E: Employed part time indicator: 0No 1Yes"

gen notInPaidJob=.
replace notInPaidJob=0 if employment_status=="Full-Time"
replace notInPaidJob=1 if employment_status=="Not in paid work (e.g. homemaker', 'retired or disabled)"
replace notInPaidJob=0 if employment_status=="Other"
replace notInPaidJob=0 if employment_status=="Due to start a new job within the next month"
replace notInPaidJob=0 if employment_status=="Part-Time"
replace notInPaidJob=0 if employment_status=="Unemployed (and job seeking)"
label variable notInPaidJob "E: Not in paid job indicator: 0No 1Yes"

gen otheremployment=.
replace otheremployment=0 if employment_status=="Full-Time"
replace otheremployment=0 if employment_status=="Not in paid work (e.g. homemaker', 'retired or disabled)"
replace otheremployment=1 if employment_status=="Other"
replace otheremployment=1 if employment_status=="Due to start a new job within the next month"
replace otheremployment=0 if employment_status=="Part-Time"
replace otheremployment=0 if employment_status=="Unemployed (and job seeking)"
label variable otheremployment "E: Other employement status indicator: 0No 1Yes"

** Create variable to identify each study, and ID variable (6,000,000 range 
* denotes IDs in Study 3)
gen study=6
gen id=6000000 + _n
label variable study "Study: 1Study1 2Study2 3Study3 4Study4 5Study5 6Study6"
label variable id "Worker ID: 1,000,000 range for Study 1, 2,000,000 for Study 2,..."

** Create treatment categories similar to those without inequality in other studies (for parameter estimation in Appendix)
gen low_equal=0
replace low_equal=1 if low==1 | low_random==1
gen high_equal=0
replace high_equal=1 if high_random==1
gen low_unequal=0
gen lowwage_category=0 if low_equal==1
gen low_wage=0
replace low_wage=1 if lowwage_category!=.
gen highwage_category=0 if high_equal==1
gen high_wage=0
replace high_wage=1 if highwage_category!=.

** Create alternative wage variable
gen w=3 if low_wage==1
replace w=6 if high_wage==1
label variable w "Piece-rate wage in approx. 2018 equivalent: 3(low-wage) 6(high-wage)"

** Create inequality aversion variables (for parameter estimation in Appendix)
gen dis_ineq=0 
label variable dis_ineq "Disadvantageous piece-rate wage inequality"
gen adv_ineq=0
label variable adv_ineq "Advantageous piece-rate wage inequality"
gen d_dis_ineq=0 
label variable d_dis_ineq "Gender-disc disadvantageous piece-rate wage inequality"
gen d_adv_ineq=0
label variable d_adv_ineq "Gender-disc advantageous piece-rate wage inequality"

* Standardize labor supply based on LOW scheme (mean 47.024, sd 24.03009)
sum l if low==1
gen sd_l=(l-47.02)/24.03

* Provide info in label for three comprehension questions
label variable C2  "1st ans. to compr. quest. on what the task is, correct:3"
label variable C4 "1st ans. to compr. quest. on whether task has further uses for anyone, correct:4"
label variable C9 "1st ans. to compr. quest. on how we pay workers, correct:3"


** Save dataset
save ".../JPEReplicationPackageDataverse/GBR24DataCleanStudy6.dta", replace
